package com.honey.compilation.xml;

import com.honey.core.builder.CharacterBuilder;
import com.honey.core.builder.CharacterBuilderFactory;
import com.honey.core.compiler.IndentSpace;


/**
 * xml 注释  <!-- 注释内容 -->
 * @author Administrator
 *
 */
public class CommentsElement  extends TextElement {
	
	/**
	 * 构造函数
	 */
	public CommentsElement(){
		super();
	}
	
	/**
	 * 构造函数
	 * @param contents 注释内容
	 */
	public CommentsElement(String ...contents) {
		super(contents);

	}
	
	@Override
	public CharacterBuilder compiledContent(int indentLevel) {
		
		return compiledContent(indentLevel, false);
	}
	
	public CharacterBuilder compiledContent(int indentLevel, boolean isDoc) {
		CharacterBuilder answer = CharacterBuilderFactory.createC16StringBuilder();
		IndentSpace.spaceIndent(answer, indentLevel);
  		answer.append("<!-- ");
		if(isDoc){
	   		 for(String content : getContents()){
	   			 IndentSpace.newSpace(answer, indentLevel);
	   			 answer.append("    ").append(content);
	   		 }
	   		 IndentSpace.newSpace(answer, indentLevel);
	   		 answer.append("-->");
	   		 IndentSpace.newLine(answer);
		}else{
			if(getContents().size()>1){
				indentLevel ++;
				IndentSpace.newLine(answer);
				for(String content : getContents()){
					IndentSpace.spaceIndent(answer, indentLevel);
					answer.append(content);
					IndentSpace.newLine(answer);
				}
				indentLevel --;
				IndentSpace.spaceIndent(answer, indentLevel);
			}else{
				answer.append(getContents().get(0));
			}
			answer.append(" -->");
		}
		
		
		
		return answer;
	}
	
}
